package com.example.translateappjava.Utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.translateappjava.R;
import com.example.translateappjava.Utils.DataItem;

import java.util.List;

public class DataItemAdaptor extends ArrayAdapter<DataItem> {

    private Context context;
    private int resource;
    private List<DataItem> dataItemList;

    public DataItemAdaptor(@NonNull Context context, int resource, @NonNull List<DataItem> dataItemList) {
        super(context, resource, dataItemList);
        this.context = context;
        this.resource = resource;
        this.dataItemList = dataItemList;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(resource, parent, false);
        }

        DataItem currentItem = dataItemList.get(position);

        ImageView itemImage = convertView.findViewById(R.id.item_image);
        TextView itemText = convertView.findViewById(R.id.item_text);

        itemImage.setImageResource(currentItem.getImageId());
        itemText.setText(currentItem.getContext());

        return convertView;
    }
}